<?php if (!defined('THINK_PATH')) exit(); /*a:3:{s:74:"D:\phpstudy_pro\WWW\xqyw\public/../application/system\view\user\index.html";i:1715413015;s:65:"D:\phpstudy_pro\WWW\xqyw\application\system\view\public\head.html";i:1715411275;s:67:"D:\phpstudy_pro\WWW\xqyw\application\system\view\public\footer.html";i:1704857607;}*/ ?>
<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>后台管理系统</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta http-equiv="Access-Control-Allow-Origin" content="*">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="icon" href="/static/system/images/favicon.ico">
	<link rel="stylesheet" href="/static/system/css/themes/default.css" media="all">
	<link rel="stylesheet" href="/static/system/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
	<link rel="stylesheet" href="/static/system/lib/layui-v2.9.9/css/layui.css" media="all">
	<link rel="stylesheet" href="/static/system/css/public.css" media="all">
	<link rel="stylesheet" href="/static/system/css/layuimini.css?v=2.0.4.2" media="all">

	<script src="/static/system/lib/layui-v2.9.9/layui.js" charset="utf-8"></script>
	<script src="/static/system/js/lay-config.js?v=2.0.0" charset="utf-8"></script>
	<script>
        // 是否开启刷新记忆tab功能
        // var is_remember = false;
    </script>
	<!--[if lt IE 9]>
		<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
		<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
		<![endif]-->
	<style id="layuimini-bg-color">
	</style>
</head>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">

            <fieldset class="table-search-fieldset">
                <legend>搜索信息</legend>
                <div style="margin: 10px 10px 10px 10px">
                    <form class="layui-form layui-form-pane" action="">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">用户姓名</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="username" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                    lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                            </div>
                        </div>
                    </form>
                </div>
            </fieldset>

            <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
            </div>
        </script>

            <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>


            <!-- 原生 select 模板（推荐） -->
            <script type="text/html" id="TPL-select-primary">
                {{#  var levelList = d.levelList || []; }}
                <select name="level" class="layui-border select-demo-primary" lay-ignore>
                <option value="">未指定</option>
                    {{#  layui.each(levelList, function(i, v){ }}
                    <option value="{{= v.id }}" {{= v.id === d.level ? 'selected' : '' }}>{{= v.grade }}</option>
                {{#  }); }}
                </select> 
            </script>
            <script type="text/html" id="currentTableBar">
                <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
                <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="more">
                    更多 
                    <i class="layui-icon layui-icon-down"></i>
                </a>
        </script>

        </div>
    </div>
    <script type="text/html" id="status-templet-switch">
        <input type="checkbox" name="status" value="{{= d.id }}" title="启用中|已关闭" lay-skin="switch" lay-filter="demo-templet-status" {{= d.status == 1 ? "checked" : "" }}>
    </script>
    <script>
        layui.use(['form', 'table','dropdown'], function () {
            var $ = layui.jquery,
                form = layui.form,
                dropdown = layui.dropdown,
                table = layui.table;

             table.render({
                elem: '#currentTableId',
                url: '<?php echo url("index"); ?>',
                method: 'POST',
                toolbar: '#toolbarDemo',
                defaultToolbar: ['filter', 'exports', 'print', {
                    title: '提示',
                    layEvent: 'LAYTABLE_TIPS',
                    icon: 'layui-icon-tips'
                }],
                cols: [[
                    {field: 'id', title: '编号',fixed: true, sort: true,style: "height:50px;"},
                    {field: 'avatar', title: '头像', },
                    {field: 'nickname', title: '昵称'},
                    {field: 'phone', title: '手机号码'},
                    {field: 'openid', title: 'openid', hide:true},
                    {field: 'sex', title: '性别',  sort: true},
                    {field: 'money', title: '余额',  sort: true},
                    {field: 'score', title: '积分',  sort: true},
                    {field: 'level', title: '级别', templet: '#TPL-select-primary'},
                    {field: 'status', title: '状态', align: 'center', width: 100, templet: '#status-templet-switch' },
                    {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center" }
                ]],
                done: function(res, curr, count) {
                    var options = this;

                    // 获取当前行数据
                    table.getRowData = function(tableId, elem){
                        var index = $(elem).closest('tr').data('index');
                        return table.cache[tableId][index] || {};
                    };

                    // 原生 select 事件
                    var tableViewElem = this.elem.next();
                    tableViewElem.find('.select-demo-primary').on('change', function(){
                        var value = this.value; // 获取选中项 value
                        var data = table.getRowData(options.id, this); // 获取当前行数据(如 id 等字段，以作为数据修改的索引)
                        // 更新数据中对应的字段
                        data.level = value; 
                        // 修改用户等级
                        $.post('<?php echo url("update"); ?>',{id:data.id,field:'level',value:data.level},function(res) {
                                if(res.code > 0) {
                                   layer.msg(res.msg,{icon:1});
                                }else {
                                   layer.msg(res.msg,{icon: 2});
                                }
                        });
                    });
                },
                limits: [10, 15, 20, 25, 50, 100],
                limit: 15,
                page: {
                    theme: '#1E9FFF'
                },
                skin: 'line'
            });

            // 监听搜索操作
            form.on('submit(data-search-btn)', function (data) {
                var data = data.field;
                //执行搜索重载
                table.reload('currentTableId', {
                    page: {
                        curr: 1,
                        theme: '#1E9FFF'
                    }
                    , where: {
                        key: data.username,
                        group_id: data.auth_group
                    }
                }, 'data');

                return false;
            });

            /**
             * toolbar监听事件
             */
            table.on('toolbar(currentTableFilter)', function (obj) {
                if (obj.event === 'add') {  // 监听添加操作
                    var index = layer.open({
                        title: '添加用户',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: true,
                        area: ['100%', '100%'],
                        content: '<?php echo url("add"); ?>',
                    });
                    $(window).on("resize", function () {
                        layer.full(index);
                    });
                }
            });

            //监听表格复选框选择
            table.on('checkbox(currentTableFilter)', function (obj) {
                console.log(obj)
            });

            table.on('tool(currentTableFilter)', function (obj) {
                var data = obj.data;
                if (obj.event === 'edit') {

                    var index = layer.open({
                        title: '编辑用户',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: true,
                        area: ['100%', '100%'],
                        content: '<?php echo url("edit"); ?>?id=' + data.id,
                    });
                    $(window).on("resize", function () {
                        layer.full(index);
                    });
                    return false;
                } else if(obj.event === 'more'){
                        // 更多 - 下拉菜单
                        dropdown.render({
                            elem: this, // 触发事件的 DOM 对象
                            show: true, // 外部事件触发即显示
                            data: [{
                            title: '余额积分',
                            id: 'detail'
                            },{
                            title: '删除',
                            id: 'del'
                            }],
                            click: function(menudata){
                            if(menudata.id === 'detail'){
                                var index = layer.open({
                                    title: '编辑其他',
                                    type: 2,
                                    shade: 0.2,
                                    maxmin: true,
                                    shadeClose: true,
                                    area: ['400px', '600px'],
                                    content: '<?php echo url("set_money_intergral"); ?>?id=' + data.id,
                                });
                                $(window).on("resize", function () {
                                    layer.full(index);
                                });
                                return false;
                                
                            } else if(menudata.id === 'del'){
                                layer.confirm('真的删除用户 [id: '+ data.id +'] 么', function(index){
                                    $.post('<?php echo url("del"); ?>',{id: data.id},function(res) {
                                        if(res.code > 0) {
                                            obj.del();
                                            layer.close(index);
                                        }else {
                                            layer.msg(res.msg, { time: 1000, icon: 2 });
                                            return false;
                                        }
                                     
                                    }); 
                                });
                            } 
                            },
                            align: 'right', // 右对齐弹出
                            style: 'box-shadow: 1px 1px 10px rgb(0 0 0 / 12%);' // 设置额外样式
                        })
                }
            });


            /**
              * 状态点击监听- 开关操作
            */
            form.on('switch(demo-templet-status)', function (obj) {
                var loading = layer.load(1, { shade: [0.1, '#fff'] });
                var id = this.value;
                $.post('<?php echo url("admin/state"); ?>', { 'id': id }, function (res) {
                    layer.close(loading);
                    if (res.code > 0) {
                        tableIn.reload();
                    } else {
                        layer.msg('操作失败！', { time: 1000, icon: 2 });
                        return false;
                    }
                });

            });

        });
    </script>

    <script>
    layui.use(['jquery', 'layer', 'miniAdmin'], function () {
        var $ = layui.jquery,
            layer = layui.layer,
            miniAdmin = layui.miniAdmin,
            iniUrl = {};
        var options = {
            iniUrl: "<?php echo url('index/getSystemInit'); ?>", // 初始化接口
            clearUrl: "clear", // 缓存清理接口
            urlHashLocation: true, // 是否打开hash定位
            bgColorDefault: false, // 主题默认配置
            multiModule: true, // 是否开启多模块
            menuChildOpen: false, // 是否默认展开菜单
            loadingTime: 0, // 初始化加载时间
            pageAnim: true, // iframe窗口动画
            maxTabNum: 20, // 最大的tab打开数量
        };
        miniAdmin.render(options);
        $('.login-out').on("click", function () {
            $.post("<?php echo url('Login/outlogin'); ?>",{},function(res) {
                layer.msg('退出登录成功', function () {
                    window.location = 'Login/index';
                });
            })

        });
    });
</script>
<script>
    //预览大小根据原图的大小决定弹窗的大小
    function previewImg(obj) {
        var img = new Image();
        img.src = obj.src;
        var height = img.height + 50; //获取图片高度
        var width = img.width; //获取图片宽度
        var imgHtml = "<img src='" + obj.src + "' width='100%' height='100%'/>";
        //弹出层
        layer.open({
            type: 1,
            shade: 0.8,
            offset: 'auto',
            // area: [height + 'px', width + 'px'],
            area: ['800px', '600px'],
            shadeClose: true,
            scrollbar: false,
            title: '', //不显示标题
            content: imgHtml, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
            cancel: function () {
                //layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构', { time: 5000, icon: 6 });
            }
        });
    }
</script>
</body>

</html>